//
//  BBuyNowShopStoreHeaderView.m
//  DistributorAB
//
//  Created by LZY on 2019/10/10.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BBuyNowShopStoreHeaderView.h"

@interface BBuyNowShopStoreHeaderView ()
@property (nonatomic, strong) UIButton *btnSynthesize;//综合
@property (nonatomic, strong) UIButton *btnSales;//销量
@property (nonatomic, strong) UIButton *btnSelected;//选中
@end

@implementation BBuyNowShopStoreHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    self.backgroundColor = kColorWithHex(0xffffff);
    _btnSynthesize = [UIButton buttonWithType:UIButtonTypeCustom];
    _btnSynthesize.frame = CGRectMake(0, 0, kScreen_Width / 2.0, 32);
    _btnSynthesize.tag = 200;
    [_btnSynthesize setTitle:@"综合" forState:UIControlStateNormal];
    [_btnSynthesize setTitleColor:kColorWithHex(0x999999) forState:UIControlStateNormal];
    [_btnSynthesize setTitleColor:kColorWithHex(0x70be68) forState:UIControlStateSelected];
    _btnSynthesize.titleLabel.font = [UIFont systemFontOfSize:12];
    _btnSynthesize.selected = YES;
    _btnSelected = _btnSynthesize;
    [_btnSynthesize addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnSynthesize];
    
    _btnSales = [UIButton buttonWithType:UIButtonTypeCustom];
    _btnSales.frame = CGRectMake(kScreen_Width / 2.0, 0, kScreen_Width / 2.0, 32);
    _btnSales.tag = 201;
    [_btnSales setTitle:@"销量" forState:UIControlStateNormal];
    [_btnSales setTitleColor:kColorWithHex(0x999999) forState:UIControlStateNormal];
    [_btnSales setTitleColor:kColorWithHex(0x70be68) forState:UIControlStateSelected];
    _btnSales.titleLabel.font = [UIFont systemFontOfSize:12];
    [_btnSales addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnSales];
    
}
#pragma mark - 交互事件
- (void)btnClickAction:(UIButton *)sender{
    NSInteger tag = sender.tag;
    if (tag != _btnSelected.tag) {
        _btnSelected.selected = NO;
        sender.selected = YES;
        _btnSelected = sender;
        if (self.delegate && [self.delegate respondsToSelector:@selector(headerViewBtnClick:)]) {
            [self.delegate headerViewBtnClick:tag];
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
